<template>
  <HomePanel title="热门品牌" sub-title="国际经典 品质保证" ref="target">
    <template v-slot:right>
      <a @click="toggole(-1)" :class="{disabled:page===0}" href="javascript:;" class="iconfont icon-angle-left prev"></a>
      <a @click="toggole(1)" :class="{disabled:page===1}" href="javascript:;" class="iconfont icon-angle-right next"></a>
    </template>
    <div class="box">
      <transition name="fade">
        <ul v-if="brands && brands.length" class="list" :style="{transform:`translateX(${-page*1240}px)`}">
          <li v-for="item in brands" :key="item.id">
            <RouterLink to="/">
              <img v-lazy="item.picture" alt="">
            </RouterLink>
          </li>
        </ul>
        <HomeSkeleton v-else></HomeSkeleton>
      </transition>
    </div>
  </HomePanel>
</template>

<script lang="ts">
export default {
  name: 'HomeBrand'
}
</script>
<script setup lang="ts">
import { findBrand } from '@/api/home'
import HomePanel from './homePanel.vue'
import HomeSkeleton from './homeSkeleton.vue'
import { ref } from 'vue'
import { useLazyData } from '@/hooks'

const {target, result: brands} = useLazyData(()=>findBrand(10))
// 当前页数(只有0和1页)
const page = ref(0)
const toggole = (step: number)=> {
  const newPage = page.value + step
  if(newPage < 0 || newPage > 1) return
  page.value = newPage
}
</script>

<style scoped lang='less'>
.skeleton {
  width: 100%;
  display: flex;
  .item {
    margin-right: 10px;
    &:nth-child(5n) {
      margin-right: 0;
    }
  }
}
.home-panel {
  background:#f5f5f5
}
.iconfont {
  width: 20px;
  height: 20px;
  background: #ccc;
  color: #fff;
  display: inline-block;
  text-align: center;
  margin-left: 5px;
  background: @xtxColor;
  &::before {
    font-size: 12px;
    position: relative;
    top: -2px
  }
  &.disabled {
    background: #ccc;
    cursor: not-allowed;
  }
}
.box {
  display: flex;
  width: 100%;
  height: 345px;
  overflow: hidden;
  padding-bottom: 40px;
  .list {
    width: 200%;
    display: flex;
    transition: all 1s;
    li {
      margin-right: 10px;
      width: 240px;
      &:nth-child(5n) {
        margin-right: 0;
      }
      img {
        width: 240px;
        height: 305px;
      }
    }
  }
}
</style>
